package com.baichuan.zntx.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Getter
@AllArgsConstructor
public enum MessageEnum {
    error(-1, "非法消息"),
    data(1, "数据消息"),
    id(2, "ID设置"),
    rfid(3, "RFID设置");

    public final Integer type;
    public final String content;

    public static MessageEnum getStructureEnum(BaseMessage message) {
        Integer type = Optional.ofNullable(message)
            .map(BaseMessage::getMsgType)
            .orElse(0);
        if (type == 0) {
            return null;
        } else {
            List<MessageEnum> objectEnums = Arrays.stream(MessageEnum.values())
                .filter((item) -> Objects.equals(item.getType(), type))
                .distinct()
                .toList();
            if (!objectEnums.isEmpty()) {
                return objectEnums.get(0);
            }
            return null;
        }
    }

}
